﻿using System;
using LeopardAOP.Sample.ExceptionHandling;
using LeopardAOP.Sample.Logging;
using LeopardAOP.Sample.TestData;

namespace LeopardAOP.Sample
{
    class Program
    {
        static void Main(string[] args)
        {
            // hello world example
            // 1.OnInvoke
            // 2.OnEntry
            // 3.OnSuccess
            // 4.OnExit
            dynamic helloWorld = new HelloWorld.HelloWorld();
            string text = "test";
            helloWorld.PrintIfArgNotNull(text);
            helloWorld.PrintIfArgNotNull(null);

            helloWorld.HelloWorldCall();           

            // exception handling example
            // 1. OnException
            dynamic publicService = new PublicService
            {
                ServiceName = "TestService",
                Port = 1234,
                SessionId = "123908sdfhjkgdfg"
            };

            var sendEntity = new TestEntity { Name = "send", Number = 1 };

            try
            {
                publicService.Send(sendEntity);
            }
            catch (Exception ex)
            {
                Console.WriteLine("We catched original exception after 'exception aspect' did his job.");
            }

            // logging example
            // 1. Catching arguments change
            var entity = new TestEntity { Name = "Jon", Number = 99 };
            dynamic repository = new TestRepository();
            repository.Save(entity);
            
            Console.Read();
        }
    }
}
